package com.genITeam.ria.controller;

import javax.servlet.ServletException;

/*
 * ControllerServlet.java
 *
 * Created on June 23, 2006, 10:28 AM
 */

import java.io.*;
import java.util.ArrayList;

import javax.servlet.http.*;

import com.genITeam.ria.actions.ChatRoomAction;
import com.genITeam.ria.actions.CreateThreadAction;
import com.genITeam.ria.actions.EventAction;
import com.genITeam.ria.actions.HomeAction;
import com.genITeam.ria.actions.LoginAction;
import com.genITeam.ria.actions.MemberAction;
import com.genITeam.ria.actions.PersonalMessageAction;
import com.genITeam.ria.actions.ReplyThreadAction;
import com.genITeam.ria.actions.RightsManagementAction;
import com.genITeam.ria.actions.SearchForumAction;
import com.genITeam.ria.actions.ThreadAction;
import com.genITeam.ria.actions.UploadFileAction;
import com.genITeam.ria.actions.ViewForumAction;


public class ControllerServlet extends HttpServlet {
    
	ArrayList roomUsers;
	ArrayList chatMessages;
	
	
	
    public ControllerServlet() {
		super();
		roomUsers = new ArrayList() ;
		chatMessages = new ArrayList() ;
	}

	// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        this.doPost(request,response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String action = request.getParameter("action");       
        
    try {
    	System.out.println("in controller\n\n\n");
        //    System.out.println(new java.util.Date().getTime() + "action Type : " + action);
            if(action.equalsIgnoreCase("homeFavouriteForum")){
            	HomeAction homeAction= new HomeAction();
            	homeAction.handleFavouriteForum(request, response);
            }else if(action.equalsIgnoreCase("homeMyPost")){
            	HomeAction homeAction= new HomeAction();
            	homeAction.handleMyPost(request, response);
            }else if(action.equalsIgnoreCase("homeBuddies")){
            	HomeAction homeAction= new HomeAction();
            	homeAction.handleBuddiesData(request, response);
            }else if(action.equalsIgnoreCase("createThread")){
            	CreateThreadAction createThreadAction = new CreateThreadAction();
            	createThreadAction.handleCreateThread(request, response, getServletContext().getRealPath("/") );
            }else if(action.equalsIgnoreCase("viewForum")){
            	ViewForumAction viewForumAction = new ViewForumAction();
            	viewForumAction.handleViewForum(request, response); 
            }else if(action.equalsIgnoreCase("fourmthread")){
            	ThreadAction  ta = new ThreadAction () ;
            	ta.handleForumThread(request, response) ;
            }else if(action.equalsIgnoreCase("threadpost")){
            	ThreadAction ta = new ThreadAction () ;
            	ta.handleThreadPosts(request, response) ;
            }else if("replyThread".equalsIgnoreCase(action)) {
            	System.out.println("In Reply Thread Action If");
            	ReplyThreadAction replyThreadAction=new ReplyThreadAction();
            	replyThreadAction.handleReplyThread(request,response, getServletContext().getRealPath("/") );            	
            }else if(action.equalsIgnoreCase("uploadFile")) {
            	System.out.println("Upload File sdf dasfb ");
            	UploadFileAction uploadFileAction = new UploadFileAction();
            	uploadFileAction.handleUploadFile(request,response,  getServletContext().getRealPath("/"));            	
            }else if(action.equalsIgnoreCase("createUser")) {
            	System.out.println("UserCreate controller");
            	MemberAction memberAction=new MemberAction();
            	memberAction.handleCreateMember(request,response);            		            	
            } else if(action.equalsIgnoreCase("updateForum")) {
            	System.out.println("View Forum Update");
            	ViewForumAction viewForumAction = new ViewForumAction();
            	viewForumAction.handleUpdateViewForum(request,response);            	 
            }else if(action.equalsIgnoreCase("addForum")) {
            	System.out.println("View Forum Add New Forum");
            	ViewForumAction viewForumAction = new ViewForumAction();
            	viewForumAction.handleAddViewForum(request,response);            	 
            }else if(action.equalsIgnoreCase("personalMessage")) {
            	System.out.println("personalMessage controller");
            	PersonalMessageAction personalMessageAction = new PersonalMessageAction();
            	personalMessageAction.handlePersonalMessage(request, response);
            }else if(action.equalsIgnoreCase("events")) {
            	System.out.println("events controller");
            	EventAction eventAction = new EventAction();
            	eventAction.handleEvent(request, response);
            }else if(action.equalsIgnoreCase("getRoomList")) {
            	System.out.println("events controller");
            	ThreadAction ta = new ThreadAction () ;
            	ta.handleGetRoomList(request, response) ;
            }else if(action.equalsIgnoreCase("addBuddy")) {
            	System.out.println("addBuddy controller");
             	MemberAction memberAction=new MemberAction();
                memberAction.handleAddBuddy(request,response);
            }else if(action.equalsIgnoreCase("searchForum")) {
            	System.out.println("searchForum controller");
             	SearchForumAction searchForumAction = new SearchForumAction();
             	searchForumAction.handleSearchForum(request,response);
            }else if(action.equalsIgnoreCase("addUser")) {
            	System.out.println("events controller");            	
            	ChatRoomAction cra = new ChatRoomAction() ;
            	cra.handleAddUser(request, response, roomUsers) ;
            }else if(action.equalsIgnoreCase("removeUser")) {
            	System.out.println("events controller");            	
            	ChatRoomAction cra = new ChatRoomAction() ;
            	cra.handleRemoveUser(request, response, roomUsers) ;
            }else if(action.equalsIgnoreCase("getUserList")) {
            	System.out.println("events controller");            	
            	ChatRoomAction cra = new ChatRoomAction() ;
            	cra.handleGetUserList(request, response, roomUsers) ;
            }else if(action.equalsIgnoreCase("addMessage")) {
            	System.out.println("events controller");            	
            	ChatRoomAction cra = new ChatRoomAction() ;
            	cra.handleAddMessage(request, response, chatMessages) ;
            }else if(action.equalsIgnoreCase("getMessages")) {
            	System.out.println("events controller");            	
            	ChatRoomAction cra = new ChatRoomAction() ;
            	cra.handleGetMessages(request, response, chatMessages) ;
            }else if(action.equalsIgnoreCase("login")) {
            	System.out.println("login controller");            	
            	LoginAction loginAction = new LoginAction();
            	loginAction.handleLoginVerification(request, response);
            }else if(action.equalsIgnoreCase("updateProfile")) {
            	System.out.println("Update Profile inside controller");
             	MemberAction memberAction=new MemberAction();
                memberAction.handleUpdateProfile(request,response);
             	//            	
            	// 	ChatRoomAction cra = new ChatRoomAction() ;
            }else if(action.equalsIgnoreCase("viewProfile")) {
            	System.out.println("view  Profile inside controller");
             	MemberAction memberAction=new MemberAction();
                memberAction.handleviewProfile(request,response);
             	
            }
            else if(action.equalsIgnoreCase("deleteThread")) {
            	System.out.println("Delete thread inside controller");
             	ThreadAction threadAction = new ThreadAction();
             	threadAction.handleDeleteThread(request,response);
             	
            }
            else if(action.equalsIgnoreCase("deletePost")) {
            	System.out.println("Delete Post inside controller");
             	ThreadAction threadAction = new ThreadAction();
             	threadAction.handleDeletePosts(request,response);
             	
            }
            else if(action.equalsIgnoreCase("banMember")) {
            	System.out.println("Ban Member inside controller");
            	MemberAction memberAction = new MemberAction();
            	memberAction.handleBanMember(request,response);
            }
            else if(action.equalsIgnoreCase("userRequestView")) {
            	System.out.println("User Request to join inside controller");
            	RightsManagementAction rightsManagementAction= new RightsManagementAction();
            	rightsManagementAction.handleUserRequestSubmission(request,response);
            }else if(action.equalsIgnoreCase("adminRequestView")){
    			System.out.println("fakhri\n\n\n\n in controller");
            	RightsManagementAction rightsManagementAction= new RightsManagementAction();
            	rightsManagementAction.handleAdminRequestView(request,response);
            	
            }else if(action.equalsIgnoreCase("approveRequest")){
    			System.out.println("approve request in controller");
            	RightsManagementAction rightsManagementAction= new RightsManagementAction();
            	rightsManagementAction.handleApproveRequestSubmission(request,response);
            	
            }
            else if(action.equalsIgnoreCase("rejectRequest")){
    			System.out.println("approve request in controller");
            	RightsManagementAction rightsManagementAction= new RightsManagementAction();
            	rightsManagementAction.handleRejectRequestSubmission(request,response);
            }
          
          
            
            else{
            	System.out.println("In Else");            	
                System.out.print(action+" = abc");
            }
        }
        catch (Exception e) {
                e.printStackTrace();			
        }
    }

    public static void main (String[] args){
    	
    }
}
